package Chapter2.Comparing.c4;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PasswordRegex {
    public static void main(String[] args) {
        /*String str = "^(?![0-9]+$)(?![a-zA-Z]+$)\\w{6,20}$";
        System.out.println("323324242".matches(str));

        String str1 = "^\\d+(\\.\\d+)?";
        System.out.println("2323232".matches(str1));
    }*/

        String str = "zhangsan    xiaoqian      wangwu";
        String[] strs = str.split(" +");
        for (String string : strs) {
            System.out.println(string);
        }

        String str2 = "zhangsanqqqqqqxiaoqianeeeeeewangwu";
        String[] strs2 = str2.split("(.)\\1+");
        for (String string: strs2) {
            System.out.println(string);
        }

        String str3 = "zhangsanQQQQQQQQQlIisiUUUUUwangwu";
        str3 = str3.replaceAll("(.)\\1+","$1");
        System.out.println(str3);

        String str4 = "13211681322";
        str4 =str4.replaceAll("(\\d{3})(\\d{4})(\\d{4})","$1****$3");
        System.out.println(str4);

        String str5 = "Tom Jack Ann Alice Elie Wan!";
        String regex = "\\b[a-zA-Z]{3}\\b";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str5);

        System.out.println(str5+"\n\n");
        while(m.find()){
            System.out.println(m.group());
            System.out.println("字符区间：：："+m.start()+":"+m.end());
        }

    }
}
